package board;

public class Piece {

	private final static int EMPTY_COLOR = 1337;
	public final static int WHITE = 1;
	public final static int BLACK = 0;

	/**
	 * Returns an empty tile/piece occupying the position x,y
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public static Piece makeEmptyPiece(int x, int y) {
		return new Piece(EMPTY_COLOR, x, y);
	}

	public final int color;
	public final int xpos;
	public final int ypos;

	/**
	 * Constructor for a black or white piece.
	 * 
	 * @param color
	 * @param x
	 * @param y
	 */
	public Piece(int color, int x, int y) {
		this.color = color;
		xpos = x;
		ypos = y;
	}

	/**
	 * Returns whether this is an empty piece/tile or not.
	 * 
	 * @return
	 */
	public boolean isEmpty() {
		return color == EMPTY_COLOR;
	}

	/**
	 * Returns whether this piece occupies a goal row
	 */
	public boolean goalRow() {
		if (color == Piece.BLACK && ypos == 7) { // check if it is on black goal
													// row
			return true;
		}
		if (color == Piece.WHITE && xpos == 7) { // check if it is on white goal
													// row
			return true;
		}
		return false;
	}

	/**
	 * Returns whether this piece occupies a home row
	 */
	public boolean homeRow() {
		if (color == Piece.BLACK && ypos == 0) { // check if it is on black goal
													// row
			return true;
		}
		if (color == Piece.WHITE && xpos == 0) { // check if it is on white goal
													// row
			return true;
		}
		return false;
	}

	public String toString() {
		if (color == BLACK) {
			return "<B" + xpos + "," + ypos + ">";
		} else if (color == WHITE) {
			return "<W" + xpos + "," + ypos + ">";
		} else {
			return "<E" + xpos + "," + ypos + ">";
		}
	}
}
